<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">

      <el-form-item label="回复状态" prop="isReply">
        <el-select v-model="queryParams.isReply">
		   <el-option value="0" label="未回复">未回复</el-option>
		   <el-option value="1" label="已回复">已回复</el-option>
		</el-select>
      </el-form-item>
      
      <el-form-item label="起始日期" prop="startDate">
        <el-date-picker clearable
          v-model="startDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择起始日期">
        </el-date-picker>
      </el-form-item>
	  <el-form-item label="截止日期" prop="endDate">
	    <el-date-picker clearable
	      v-model="endDate"
	      type="date"
	      value-format="yyyy-MM-dd"
	      placeholder="请选择截止日期">
	    </el-date-picker>
	  </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:unburden:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:unburden:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:unburden:remove']"
        >删除</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="unburdenList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="序号" align="center" prop="unburdenId" />
      <el-table-column label="登录名" align="center" prop="userName" />
	  <el-table-column label="姓名" align="center" prop="createName" />
	  <el-table-column label="性别" align="center" prop="sex" >
		  <template slot-scope="scope">
		  			<span>{{ scope.row.sex==0 ? '女': scope.row.sex==1 ? '男':'未知'  }}</span>
		  		  </template>
		  </el-table-column>
	  <el-table-column label="部门" align="center" prop="dept.deptName" />
      <el-table-column label="倾诉主题" align="center" prop="unburdenTypeName" />
      <el-table-column label="留言时间" align="center" prop="createTime" width="180">
		<template slot-scope="scope">
			<span>{{ parseTime(scope.row.createTime, '{y}/{m}/{d} {h}:{i}') }}</span>
		  </template>
	</el-table-column>
      <el-table-column label="回复状态" align="center" prop="isReply" >
		<template slot-scope="scope">
			<span>{{ scope.row.isReply ? '已回复':'未回复'  }}</span>
		  </template>
	  </el-table-column>
      <el-table-column label="回复人" align="center" prop="replyName" >
	  </el-table-column>  
      <el-table-column label="回复时间" align="center" prop="replyTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.replyTime, '{y}/{m}/{d} {h}:{i}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:unburden:edit']"
			v-if="scope.row.isReply==0"
          >修改</el-button>
		  <el-button
		    size="mini"
		    type="text"
		    icon="el-icon-view"
		    @click="handleUpdate(scope.row)"
		    v-hasPermi="['system:unburden:edit']"
		  			v-else
		  >查看</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:unburden:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改在线倾诉对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="倾诉主题" prop="unburdenTypeName">
		  <el-select v-model="form.unburdenTypeName" name="unburdenTypeName" @change="unburdenTypeChange">
		      <el-option v-for="(item,idx) in qaTypeList" 
		      :label="item.typeName" 
		      :value="item.qaTypeId"
		      :key="idx"
		      ></el-option>
		    </el-select>
        </el-form-item>
        <el-form-item label="倾诉内容">
          <el-input type="textarea" v-model="form.unburdenContent" :autosize="{ minRows: 5}"/>
        </el-form-item>
        <el-form-item label="联系方式" prop="mobile">
          <el-input v-model="form.mobile" placeholder="请输入联系方式" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
	
	
	<el-dialog title="查看" :visible.sync="open2" width="500px" append-to-body>
	  <el-form ref="form" :model="form" :rules="rules" label-width="80px">
	    <el-form-item label="倾诉主题" prop="unburdenTypeName">
			<el-input v-model="form.unburdenTypeName" disabled/>
	    </el-form-item>
	    <el-form-item label="倾诉内容">
		  <el-input type="textarea" v-model="form.unburdenContent" :autosize="{ minRows: 5}"/>
	    </el-form-item>
	    <el-form-item label="联系方式" prop="mobile">
	      <el-input v-model="form.mobile" disabled/>
	    </el-form-item>
		<el-form-item label="回复人" prop="replyName">
		  <el-input v-model="form.replyName" placeholder="" disabled/>
		</el-form-item>
		<el-form-item label="回复内容" prop="replyContent">
		  <el-input type="textarea" v-model="form.replyContent" :autosize="{ minRows: 5}"/>
		</el-form-item>
	  </el-form>
	</el-dialog>
  </div>
</template>

<script>
import { mylistUnburden, getUnburden, delUnburden, addUnburden, updateUnburden } from "@/api/consult/unburden";

import { selectQaType } from "@/api/consult/common";

export default {
  name: "Unburden",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 在线倾诉表格数据
      unburdenList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
	  open2: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        isReply: null,
		params: {
			
		}
      },
      // 表单参数
      form: {},
	  startDate: '',
	  endDate: '',
	  qaTypeList: [],
	  unburdenType: '',
      // 表单校验
      rules: {
        unburdenType: [
          { required: true, message: "倾诉主题为空", trigger: "blur" }
        ],
        unburdenContent: [
          { required: true, message: "倾诉内容不能为空", trigger: "blur" }
        ]
      }
    };
  },
  created() {
    this.getList();
	this.getQaTypeList();
  },
  methods: {
	  getQaTypeList() {
	    selectQaType().then(response => {
	      this.qaTypeList = response.data;
	    });
	  },
	  unburdenTypeChange(val) {
	  		this.unburdenType = val;
	  },
    /** 查询在线倾诉列表 */
    getList() {
      this.loading = true;
	  this.queryParams.params['startDate'] = this.startDate;
	  this.queryParams.params['endDate'] = this.endDate;
      mylistUnburden(this.queryParams).then(response => {
        this.unburdenList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
	  this.open2 = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        unburdenId: null,
        userName: null,
        unburdenType: null,
        unburdenContent: null,
        mobile: null,
        ceateBy: null,
        createTime: null,
        isReply: null,
        replyContent: null,
        replyBy: null,
        replyTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.unburdenId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加在线倾诉";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const unburdenId = row.unburdenId || this.ids
      getUnburden(unburdenId).then(response => {
        this.form = response.data;
		this.unburdenType = this.form.unburdenType;
		if(this.form.isReply==0)
        this.open = true;
		else
		this.open2 = true;
        this.title = "修改在线倾诉";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
			this.form['unburdenType'] = this.unburdenType;
          if (this.form.unburdenId != null) {
            updateUnburden(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addUnburden(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const unburdenIds = row.unburdenId || this.ids;
      this.$modal.confirm('是否确认删除在线倾诉编号为"' + unburdenIds + '"的数据项？').then(function() {
        return delUnburden(unburdenIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    }
  }
};
</script>
